﻿$(function() {
	sidebarToggleTrans();

	$('.site-nav-toggle').bind('click', function() {
		$('.site-nav').slideToggle(200);
	});

	$('.back-to-top').bind('click', function() {
		$('html, body').animate({
			scrollTop: $("body").offset().top
		}, 500);
	});

	$('.sidebar-toggle').bind('click', function() {
		if($(".sidebar").width() == 0) {
			$("body").css("padding-right", "320px");

			$(".site-author-image").attr('src', "img/author/" + Math.round(Math.random() * 4 + 1) + ".jpg");

			$(".sidebar").addClass("sidebar-active");

			$(".motion-element").show().addClass("fade");

			$('.sidebar-toggle-line-first').css({
				"width": "100%",
				"top": "5px",
				"transform": "rotateZ(-45deg)",
				"opacity": "1",
				"left": "0px"
			});
			$('.sidebar-toggle-line-middle').css({
				"width": "90%",
				"top": "0px",
				"transform": "rotateZ(0deg)",
				"opacity": "0",
				"left": "0px"
			});
			$('.sidebar-toggle-line-last').css({
				"width": "100%",
				"top": "-5px",
				"transform": "rotateZ(45deg)",
				"opacity": "1",
				"left": "0px"
			});
		} else {
			$("body").css("padding-right", "0px");

			$(".sidebar").removeClass("sidebar-active");

			$(".motion-element").hide();

			$('.sidebar-toggle-line-first,.sidebar-toggle-line-middle,.sidebar-toggle-line-last').css({
				"width": "100%",
				"top": "0px",
				"transform": "rotateZ(0deg)",
				"opacity": "1",
				"left": "0px"
			});
		}

	});
});

/*jqeury的css优先级比css高，会覆盖掉所有的css；包括会使伪类选择器样式失效*/
function sidebarToggleTrans() {
	var el = $(".sidebar-toggle");
	el.hover(function() {
		if($(".sidebar").width() == 0) {
			$('.sidebar-toggle-line-first').css({
				"width": "50%",
				"top": "2px",
				"transform": "rotateZ(-45deg)",
				"opacity": "1",
				"left": "0px"
			});
			$('.sidebar-toggle-line-middle').css({
				"width": "90%",
				"top": "0px",
				"transform": "rotateZ(0deg)",
				"opacity": "1",
				"left": "0px"
			});
			$('.sidebar-toggle-line-last').css({
				"width": "50%",
				"top": "-2px",
				"transform": "rotateZ(45deg)",
				"opacity": "1",
				"left": "0px"
			});
		}
	}, function() {
		if($(".sidebar").width() == 0)
			$('.sidebar-toggle-line-first,.sidebar-toggle-line-middle,.sidebar-toggle-line-last').css({
				"width": "100%",
				"top": "0px",
				"transform": "rotateZ(0deg)",
				"opacity": "1",
				"left": "0px"
			});
	});
}